package org.pasta.web.controller;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public abstract class POSController extends AbstractController {

	protected ServletContext context;
	protected HttpSession session;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	
	protected String USER_SESSION = "login-user"; 
	
	protected String MESSAGE = "message";
	
	// Popup Message Type
	protected String INFO_MSG_TYPE = "INFO";
	protected String WANRING_MSG_TYPE= "WARING";
	protected String ERROR_MSG_TYPE= "ERROR";
	

	protected abstract ModelAndView process();

	protected ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response) throws Exception {
		this.response = response;
        this.request = request;
        this.session = request.getSession();
        this.context = getServletContext();
        this.response.setContentType( getContentTypeString() );
        
        return process();
	}
	
	protected String getParameter(String paramName){
		String ret = request.getParameter(paramName) ;
		if("null".equals(ret))
			return null;
		
		return ret;
	}

	private String getContentTypeString() {
		// TODO Auto-generated method stub
		return "text/html; charset=tis-620";
	}

	public ServletContext getContext() {
		return context;
	}

	/**
	 * @param context
	 *            The context to set.
	 */
	public void setContext(ServletContext context) {
		this.context = context;
	}

	/**
	 * @return Returns the request.
	 */
	public HttpServletRequest getRequest() {
		return request;
	}

	/**
	 * @param request
	 *            The request to set.
	 */
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	/**
	 * @return Returns the response.
	 */
	public HttpServletResponse getResponse() {
		return response;
	}

	/**
	 * @param response
	 *            The response to set.
	 */
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	/**
	 * @return Returns the session.
	 */
	public HttpSession getSession() {
		return session;
	}

	/**
	 * @param session
	 *            The session to set.
	 */
	public void setSession(HttpSession session) {
		this.session = session;
	}

}
